<?php

namespace app\admin\controller\setting;

use app\admin\controller\AdminController;
use app\admin\service\setting\NoticeService;
use app\admin\validate\setting\NoticeValidate;
use think\response\Json;

/**
 * 消息管理控制器
 */
class Notice extends AdminController
{

    /**
     * 获取消息配置列表
     * @return Json
     */
    public function lists()
    {
        return $this->success(NoticeService::lists());
    }

    /**
     * 设置消息配置
     * @return Json
     */
    public function edit()
    {
        $params = (new NoticeValidate())->post()->checkParam('edit');
        $result = NoticeService::edit($params);
        if (true === $result) {
            return $this->success([], '配置成功');
        } else {
            return $this->error(NoticeService::getError());
        }
    }


    /**
     * 消息配置信息
     * @return Json
     */
    public function detail()
    {
        $param = (new NoticeValidate())->checkParam('detail');
        return $this->success(NoticeService::detail($param));
    }


    /**
     * 切换消息渠道状态
     * @return Json
     */
    public function change()
    {
        $params = (new NoticeValidate())->post()->checkParam('change');
        $result = NoticeService::change($params);
        if (true === $result) {
            return $this->success([], '切换成功');
        } else {
            return $this->error(NoticeService::getError());
        }
    }
}